package cn.benben.system.dubbo;

import cn.benben.system.model.User;
import cn.benben.system.service.UserService;
import cn.benben.core.utils.StringUtils;
import cn.benben.system.api.SysUserApi;
import cn.benben.system.api.dto.TestDTO;
import cn.benben.system.api.dto.UserResp;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DubboService
public class RemoteService implements SysUserApi {

    @Autowired
    private UserService userService;

    @Override
    public String  queryUser(TestDTO testDTO) {
        System.out.println("22222222");
        return "hello " + testDTO.getMsg();
    }

    @Override
    public UserResp queryUseByUsername(String username) {
        User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getUserName, username));
        if (StringUtils.isNull(user)) return null;
        UserResp userResp = new UserResp();
        BeanUtils.copyProperties(user,userResp);
        return userResp;
    }
}
